package com.gsx.service.Impl;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.gsx.entity.Blog_Type_User;
import com.gsx.entity.Type;
import com.gsx.mapper.TypeMapper;
import com.gsx.service.TypeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.ArrayList;
import java.util.List;

@Service
public class TypeServiceImpl implements TypeService {
    @Autowired
    private TypeMapper typeMapper;

    @Transactional
    @Override
    public int saveType(Type type) {
        return typeMapper.saveType(type);
    }

    @Override
    public Type getType(Long id) {
        return typeMapper.getType(id);
    }

    @Override
    public List<Type> getAllType(int page,int size) {
        PageHelper.startPage(page,size);
        List<Type> types=typeMapper.getListType();
        return types;
    }

    @Transactional
    @Override
    public int updateType(Type type) {
        return typeMapper.updateType(type);
    }

    @Transactional
    @Override
    public int deleteType(Long id) {
        return typeMapper.deleteType(id);
    }

    public Type getTypeByName(String name){
        return typeMapper.getTypeByName(name);
    }

    public List<Type> getAll(){
        return typeMapper.getAll();
    }

    public List<Blog_Type_User> getBlog_Type_User(Long type_id){
        return typeMapper.getBlog_Type_User(type_id);
    }
}
